package com.linpq.road.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.linpq.common.annotation.Log;
import com.linpq.common.enums.BusinessType;
import com.linpq.road.domain.RdPavementPerformance;
import com.linpq.road.service.RdPavementPerformanceService;
import com.linpq.common.core.controller.BaseController;
import com.linpq.common.core.domain.AjaxResult;
import com.linpq.common.utils.poi.ExcelUtil;
import com.linpq.common.core.page.TableDataInfo;

/**
 * 路面性能Controller
 *
 * @author linpq
 * @date 2021-07-29
 */
@Controller
@RequestMapping("/road/pavement_performance")
public class RdPavementPerformanceController extends BaseController {
    private String prefix = "road/pavement_performance";

    @Autowired
    private RdPavementPerformanceService rdPavementPerformanceService;

    @RequiresPermissions("road:pavement_performance:view")
    @GetMapping()
    public String pavement_performance() {
        return prefix + "/pavement_performance";
    }

    /**
     * 查询路面性能列表
     */
    @RequiresPermissions("road:pavement_performance:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RdPavementPerformance rdPavementPerformance) {
        startPage();
        List<RdPavementPerformance> list = rdPavementPerformanceService.selectRdPavementPerformanceList(rdPavementPerformance);
        return getDataTable(list);
    }

    /**
     * 导出路面性能列表
     */
    @RequiresPermissions("road:pavement_performance:export")
    @Log(title = "路面性能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RdPavementPerformance rdPavementPerformance) {
        List<RdPavementPerformance> list = rdPavementPerformanceService.selectRdPavementPerformanceList(rdPavementPerformance);
        ExcelUtil<RdPavementPerformance> util = new ExcelUtil<RdPavementPerformance>(RdPavementPerformance. class);
        return util.exportExcel(list, "pavement_performance");
    }

    /**
     * 新增路面性能
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存路面性能
     */
    @RequiresPermissions("road:pavement_performance:add")
    @Log(title = "路面性能", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RdPavementPerformance rdPavementPerformance) {
        return toAjax(rdPavementPerformanceService.insertRdPavementPerformance(rdPavementPerformance));
    }

    /**
     * 修改路面性能
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        RdPavementPerformance rdPavementPerformance =rdPavementPerformanceService.selectRdPavementPerformanceById(id);
        mmap.put("rdPavementPerformance", rdPavementPerformance);
        return prefix + "/edit";
    }

    /**
     * 修改保存路面性能
     */
    @RequiresPermissions("road:pavement_performance:edit")
    @Log(title = "路面性能", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RdPavementPerformance rdPavementPerformance) {
        return toAjax(rdPavementPerformanceService.updateRdPavementPerformance(rdPavementPerformance));
    }

    /**
     * 删除路面性能
     */
    @RequiresPermissions("road:pavement_performance:remove")
    @Log(title = "路面性能", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(rdPavementPerformanceService.deleteRdPavementPerformanceByIds(ids));
    }
}
